package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.License;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询护理项目列表
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult getList(@RequestParam(required = false) String name,
                                  @RequestParam(required = false) Integer status,
                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("护理项目列表查询接口，入参={},{},{},{}",name,status,pageNum,pageSize);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getList(name,status,pageNum,pageSize);
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param projectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addProjict(@RequestBody NursingProjectDto projectDto){
        log.info("新增项目接口，入参={}",projectDto);
        nursingProjectService.addProjict(projectDto);
        return success();
    }

    /**
     * 查询护理项目信息
     * @param id
     * @return
     */
    @ApiOperation("查询护理项目信息")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        log.info("查询项目信息接口，入参id={}",id);
        NursingProjectVo projectVo = nursingProjectService.getById(id);
        return success(projectVo);
    }

    /**
     * 更新护理项目信息
     * @param projectDto
     * @return
     */
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto projectDto){
        log.info("更新护理项目信息,入参={}",projectDto);
        nursingProjectService.update(projectDto);
        return success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
        log.info("删除护理项目接口，入参id={}",id);
        nursingProjectService.deleteById(id);
        return success();
    }

    /**
     * 更新停用启用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,
                                 @PathVariable Integer status){
        log.info("更新停用启用接口，入参id={},status={}",id,status);
        nursingProjectService.updateStatus(id,status);
        return success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    public ResponseResult getAll(){
        log.info("查询所有护理项目接口");
        List<NursingProjectVo> projectVos = nursingProjectService.getAll();
        return success(projectVos);
    }
}
